package com.hu.zhcc.shiro.controller.Appointment;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.Appointment.TSetmeal;
import com.hu.zhcc.shiro.service.Appointment.TSetmealService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/****
 * 套餐管理Controller
 */
@RestController
public class SetMealController {

    @Autowired
    private TSetmealService setmealService;

    /****
     * 分页及条件查询
     * @param offset
     * @param limit
     * @param value
     * @return
     */
    @GetMapping("mealMuchAll")
    private Page<TSetmeal> rmealAll(String offset, String limit, String value) {
        Map map = new HashMap();
        map.put("offset", offset);
        map.put("limit", limit);
        return setmealService.tsetMealAll(map, value);
    }

    /****
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteMealByid{id}")
    private int deleteMealByid(@PathVariable("id") int id) {
        return setmealService.deleteByPrimaryKey(id);
    }

    /****
     * 添加
     * @param tSetmeal
     * @return
     */
    @PostMapping("saveSetMeal")
    private int saveSetMeal(@RequestBody TSetmeal tSetmeal) {
        tSetmeal.setAge(tSetmeal.getSetmealUp() + "-" + tSetmeal.getSetmealDown());
        return setmealService.insertSelective(tSetmeal);
    }

    /****
     * 修改前查询
     * @param id
     * @return
     */
    @PostMapping("beforeSetMealById{id}")
    private TSetmeal beforeUpdateByid(@PathVariable("id") int id) {
        return setmealService.beforeSelectMeal(id);
    }

    /****
     * 修改
     * @param setmeal
     * @return
     */
    @PutMapping("updateSetMeal")
    private int updateSetMeal(@RequestBody TSetmeal setmeal) {
        return setmealService.updateByPrimaryKeySelective(setmeal);
    }
}
